import React, { Fragment, RefObject, useEffect, useState, useMemo, useRef, FC } from 'react'
import {
    Radio, DotLoading, SearchBar, Stepper,
    NoticeBar, Popup, CheckList, NavBar, Tag, Result,
    Form, Input, Button, Dialog, Checkbox, TextArea, DatePicker,
    CascadePicker, Selector, Slider, Switch, Cascader,
    Space, SideBar, Divider, Avatar, Grid, List, InfiniteScroll
} from 'antd-mobile'

import type { PickerActions } from 'antd-mobile/es/components/picker'
import type { DatePickerRef } from 'antd-mobile/es/components/date-picker'
import type { SearchBarRef } from 'antd-mobile/es/components/search-bar';
import type { FormInstance } from 'antd-mobile/es/components/form'
import type { CascadePickerRef } from 'antd-mobile/es/components/cascade-picker'
import type { CascaderProps, CascaderValueExtend, CascaderOption, CascaderRef, CascaderActions } from 'antd-mobile/es/components/cascader';
import { PickerValue, PickerValueExtend, PickerColumnItem, PickerColumn } from 'antd-mobile/es/components/picker-view';
import { CheckListValue } from 'antd-mobile/es/components/check-list'
import { RadioValue } from 'antd-mobile/es/components/radio';

import { setPageNavBar, useLocation, Link, useSearchParams, useNavigate,useModel } from 'alita'
import { Content, Page } from '@alita/flow';

import { checkAuthorize } from '@/utils/authorize';
import { urlPrefix, getRequestInit, postRequestInit, obsPrifix } from '@/utils/http';
import { DemoBlock } from '@/components/demos-util'
import { DATE_FOMRAT, DATE_TIME_FORMAT } from '@/constants'

import type { PageInfo, DetailResult, StrTreeItemType,  TreeItemType, WeiXinUser, LabeledEnum, Block, IdName, PageResult, Opportunity, Reimb } from '@/pages/types/type'
import { CustomerSelector } from '@/pages/customer/component'




import styles from './index.less'
import dayjs from 'dayjs'
import StaffLivings from '@/components/object-staff-living';
import { UploadStatus } from '@/components/upload';
import { DeleteButton } from '@/components/delete';
import { CascadePickerUpdatePopup } from '@/components/update';

const lastViewer = 'http://pdfviewer.billschen.com/index.html';
const legacyViewr = 'http://legacypdfviewer.billschen.com/web/viewer.html';

// 数据结构定义返回结束
export default () => {
    const navigate = useNavigate();
    const location = useLocation();
    const model = useModel('useAuthModel');
    const [searchParams, setSearchParams] = useSearchParams();
    const [tokening, setTokening] = useState<boolean>(true);
    const [tokenFail, setTokenFail] = useState<string | undefined>(undefined);
    const [authOK, setAuthOK] = useState<boolean>(false);

    // 从参数中读取到的变量
    const sid = searchParams.get('id'); // 传入参数变量
    const legacy = searchParams.get('legacy') === '1';
    useEffect(() => {
        setPageNavBar({ pagePath: location.pathname, navBar: { hideNavBar: true, pageTitle: `文件`, pageBackground: '#eee' } });
        checkAuthorize(x => setTokening(x), y => {
            console.log('token检查完成！y=', y); setAuthOK(y);
        }, z => setTokenFail(z), model);
    }, []);

    
    if (tokening) {
        return <div style={{ color: '#00b578' }}>
            <DotLoading color='currentColor' />
            <span>正在授权...</span>
        </div>;
    }

    const pdfViewer = legacy ? legacyViewr : lastViewer;

    const fileUrl = `${pdfViewer}?file=${obsPrifix}/${encodeURIComponent(encodeURIComponent(`preview-pdf/${searchParams.get('uid')}/${searchParams.get('fileName')}`))}`;

    return (<Page><Content>    
       {/* <DemoBlock padding={8}>
            
            <Grid columns={1} gap={8} style={{ marginTop: "8px" }}>
                <Grid.Item span={1}>
                    <Link to={`/paper/law-effect-level/root-apply`}>创建文件分类</Link>
                </Grid.Item>
            </Grid>
            
            <Grid columns={1} gap={8} style={{ marginTop: "8px" }}>
                <Grid.Item span={1}>
                    <Link to={`/paper/law-effect-level/descendant-apply`}>创建下级文件分类</Link>
                </Grid.Item>
            </Grid>
        </DemoBlock> */}
         <iframe style={{ width: "100%", height: "100%" }} src={fileUrl} ></iframe>


    </Content></Page>);
}
